package cake.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cake.dao.CakeImgDao;
import cake.entity.CakeImg;
import cake.entity.Comment;

public class CakeImgDaoImpl implements CakeImgDao{

	private JdbcTemplate db= new JdbcTemplate();
	
	private static class CakeImgRowMapper implements RowMapper<CakeImg>{
		public CakeImg mapRow(ResultSet rs) throws SQLException {
			return new CakeImg(rs.getInt("id"),rs.getInt("cid"),rs.getString("img"));
		}
	}
	
	
	public List<CakeImg> getImgByCid(int id) {
		String sql = "select * from cakeimg where cid = ?";
		return db.query(sql, new CakeImgRowMapper(), id);
	}
	
	public boolean deleteImgById(int id) {
		String sql="delete from cakeimg where id=?";
		return db.update(sql, id);
	}
	
	public boolean addImg(CakeImg cakeImg) {
		String sql="insert into cakeimg(cid,img) values(?,?)";
		return db.update(sql, cakeImg.getCid(),cakeImg.getImg());
	}
}
